package threads;

import gui.Supervisor;

import java.util.Random;

import javax.swing.JLabel;

import juego.Logica;
import unidad.*;

public class ThreadCrearEnemigo extends Thread 
{
	protected Random gen;
	protected Supervisor sup;
	protected boolean terminar;
	protected int oleada;
	
	public ThreadCrearEnemigo(Supervisor s)
	{
		gen = new Random();
		sup = s;
		terminar = false;
		oleada = 0;
	}
	
	public void run()
	{

		int i = 0;
		while(!terminar)
		{
			int tipoEnemigo = oleada;
			int fila = gen.nextInt(5);
			JLabel enemigo = null;
			{
				switch (tipoEnemigo) {
						case 1: 
						{
							enemigo = new JLabel("imagenes/mummy");
							break;
						}
						case 2:	
						{
							enemigo = new JLabel("imagenes/yeti");
							break;
						}
						case 3:	
						{
							enemigo = new JLabel ("imagenes/SlugGunner");
							break;
						}
						case 0:	
						{
							enemigo = new JLabel ("imagenes/medusa");
						}
					}
				if(enemigo != null)
					sup.crearUnidad(enemigo, (-1) * tipoEnemigo, fila, 9);	
			}
			try {
				Thread.sleep(5000);
			} catch (InterruptedException e) {
				e.printStackTrace();
			}
			i++;
			if(i == 5)
			{
				try {
					Thread.sleep(20000);
				} catch (InterruptedException e) {
					e.printStackTrace();
				}
				oleada = (oleada + 1);
				if(oleada == 4)
				{
					terminar();
					try {
						Thread.sleep(20000);
					} catch (InterruptedException e) {
						e.printStackTrace();
					}
					sup.gano();
					
				}
				else oleada %= 4;
				i = 0;
			}
			
		
		}
		
	}

	public void terminar()
	{
		terminar=true;
	}
}
